import type {RouteLocationNormalized} from "#vue-router";
export default defineNuxtRouteMiddleware(async (to:RouteLocationNormalized, from:RouteLocationNormalized)=>{
    if(import.meta.server)return;
    let role:number=0
    if(to.path.includes('/driver')){
        // console.log(to.path)

        await cFetch<User>('/account/api/verifyToken',{
            auth:true,
            defaultOpts:{
                method:'POST',
            }
        }).then(res=>{
            if(res.code===200){
                role=res.data[0].role
            }
        })
        if(role!=1){
            showNotify({
                message:'请先在个人中心完成司机认证',
                type: 'warning',
                duration:2500
            })
            roleStore().setRole('0')
            abortNavigation('未认证司机身份')
        }
    }
    return
})